#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/sem.h>
#include<unistd.h>
#include<fcntl.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<signal.h>
#define SEM_NAME "./sem_file"
int semid;
union senum
{
    int val;
    
};
void sighandler(int sig)
{
     semctl(semid,0,IPC_RMID);
}
void init_sem(int semid,int sem_num,int val)
{
    semctl(semid,sem_num,SETVAL,val);
}
int create_sem(int nsems)
{
    key_t key=ftok(SEM_NAME,'s');
    int  semid = semget(key,nsems,0655|IPC_CREAT);
    return semid;
}
int main(int argc,char **argv)
{
    signal(SIGINT,sighandler);
    pid_t pid;
    int fd =open("a.txt",O_WRONLY|O_CREAT,0655);
    semid = create_sem(1);
    init_sem(semid,0,1);
    return 0;
}